package serializables;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 * @Description
 * @Author zhaobaolin
 * @Date 2018/11/12
 */
public class ExternalizableExample {
    public static void main(String[] args) {
        demo();
    }

    private static void demo()
    {
        try(FileOutputStream file = new FileOutputStream("./io/src/serializables/2.txt")){
            ObjectOutputStream oos = new ObjectOutputStream(file);
            PersonExternalizableVo vo = new PersonExternalizableVo();
            vo.setId(3);
            vo.setName("张三");
            oos.writeObject(vo);
            oos.close();
        }catch (Exception e){
            e.printStackTrace();
        }
        try(FileInputStream file = new FileInputStream("./io/src/serializables/2.txt")){
            ObjectInputStream ois = new ObjectInputStream(file);
            PersonExternalizableVo personVo = (PersonExternalizableVo) ois.readObject();
            ois.close();
            System.out.println(personVo.toString());
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
